package com.shenfa.dao.systemManager.organization.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.shenfa.bean.Organization;
import com.shenfa.bean.TreeNode;
import com.shenfa.dao.systemManager.organization.OrganizationDao;

public class OrganizationDaoImpl implements OrganizationDao {

	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;
	
	@SuppressWarnings("unchecked")
	public List<Organization> getAll() {
		return sqlMapClientTemplate.queryForList("organization_manager.getAll");
	}

	@SuppressWarnings("unchecked")
	public List<Organization> getListByParent(String parentId, int start, int limit) {
		return sqlMapClientTemplate.queryForList("organization_manager.getListByParent",parentId,start,limit);
	}
	public int queryCount(String parentId) 
	{   
		try
		{
		 return (Integer)sqlMapClientTemplate.queryForObject("organization_manager.queryCount",parentId);
		
		}catch(Exception e)
		{
			e.printStackTrace();
			return -1;
		}	
	}
	
	@SuppressWarnings("unchecked")
	public String queryType(String orgNo){
		return  (String)sqlMapClientTemplate.queryForObject("organization_manager.queryDetails", orgNo);	
	}

	public void add(Organization organization) {
		sqlMapClientTemplate.insert("organization_manager.add",organization);
	}

	public void update(Organization organization) {
		sqlMapClientTemplate.update("organization_manager.update", organization);
	}

	public void delete(String id) {
		sqlMapClientTemplate.update("organization_manager.deleteById", id);
	}

	public Organization getById(String id) {
		Organization organization = (Organization) sqlMapClientTemplate.queryForObject("organization_manager.getById", id);
		return organization;
	}
	public List<TreeNode> getTree(String id){
		
		return sqlMapClientTemplate.queryForList("organization_manager.getTree", id);
	}
	
	public List<TreeNode> getTree_bydepNo(String depno){
		
		return sqlMapClientTemplate.queryForList("organization_manager.getTree_bydepNo", depno);
	}

	public List<TreeNode> getChildTree(String id) {
		return sqlMapClientTemplate.queryForList("organization_manager.getChildTree", id);
	}
}
